$(document).ready(function(){
    $("#newsletter-form").submit(function(){
        var data = $(this).serialize();
        var url = $(this).attr("action");
        //call ajax
        $.ajax({
            type : "POST",
            url : url,
            data : data,
            success : function(response){
                var resultData = $.parseJSON(response);
                if(resultData.result){ //success
                    alert("thank you!");
                    //reset form
                    $("#newsletter-form input[type=text]").val("");
                }else{
                    console.log(resultData.error);
                    alert("Please valid all fields!");
                }
            }
        });
        return false;
    });
});